<template>
  <div>

      课程题目<input type="text" v-model="title">
      课程名称<input type="text" v-model="desc">
      课程价格<input type="text" v-model="price">
      
      <van-cell-group align='center'>
            选择课程视频:<van-uploader :after-read="afterRead" />
      </van-cell-group>

      <van-cell-group align='center'>
            <video width='300' height='240' :src='src' controls='controls' autoplay='autoplay'></video>
      </van-cell-group>
  </div>
</template>

<script>
import mycate from './mycate.vue'
export default {
    data(){
        return{
            data:{},
            cid:'',
            src:'',
            desc:'',
            title:'',
            price:null,
        }
    },
    mounted(){
        // 接收参数
        this.cid=this.$route.query.cid
        console.log('课程分类是'+this.cid)
    },
    methods:{
         // 文件上传
        afterRead:function(file){
            // 定义参数
            let data=new FormData()
            data.append('file',file.file)
            data.append('title',this.title)
            data.append('desc',this.desc)
            data.append('cid',this.cid)
            data.append('price',this.price)
            // 创建实例

            const axiosInstance=this.axios.create({withCredentials:false})
            axiosInstance({method:'POST',url:'http://localhost:8000/addcourse/',data:data}).then(res=>{
                console.log(res)
                this.src='http://localhost:8000/static/upload/'+res.data.video
                
            })
        },
    }
}
</script>

<style>

</style>